package org.lql.algo.codecrush.hot100.linked;

import org.lql.algo.common.ListNode;

/**
 * @author: liangqinglong
 * @date: 2025-10-02 01:00
 * @description: 160. 相交链表 <a href="https://leetcode.cn/problems/intersection-of-two-linked-lists/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class GetIntersectionNode {

	public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
		if (headA == null || headB == null) {
			return null;
		}
		ListNode pa = headA;
		ListNode pb = headB;
		while (pa != pb) {
			pa = pa == null ? headB : pa.next;
			pb = pb == null ? headA : pb.next;
		}
		return pa;
	}
}
